/*
#include <Motion.h>
#include <GlobalVar/global_variable.h>
#include <Motion.h>
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-11-28     Administrator       the first version
 */



#include "GlobalVar.h"
#include <rtthread.h>
#include <rtdbg.h>
#include "ulog.h"


#include "Motion.h"
#include "MotionManage.h"

rt_mq_t LogMqHandle = NULL;



TASK task;

MECHINE_INFO machine_info;

SEM_MOTOR sem_motor[7];

//rt_thread_t m_run_p[7];
//rt_thread_t m_gHm_p[7];
//rt_thread_t m_lqD_p[7];


void m1gHm_task(void *parameter){tmc_driver[1]->gohome_task(parameter);}
void m2gHm_task(void *parameter){tmc_driver[1]->gohome_task(parameter);}
void m3gHm_task(void *parameter){tmc_driver[1]->gohome_task(parameter);}
void m4gHm_task(void *parameter){tmc_driver[1]->gohome_task(parameter);}
void m5gHm_task(void *parameter){tmc_driver[1]->gohome_task(parameter);}
void m6gHm_task(void *parameter){tmc_driver[1]->gohome_task(parameter);}

void m1lqD_task(void *parameter){tmc_driver[1]->liquidDet_task(parameter);}
void m2lqD_task(void *parameter){tmc_driver[1]->liquidDet_task(parameter);}
void m3lqD_task(void *parameter){tmc_driver[1]->liquidDet_task(parameter);}
void m4lqD_task(void *parameter){tmc_driver[1]->liquidDet_task(parameter);}
void m5lqD_task(void *parameter){tmc_driver[1]->liquidDet_task(parameter);}
void m6lqD_task(void *parameter){tmc_driver[1]->liquidDet_task(parameter);}




//void Func(void);   /*声明一个函数*/


void abc()
{
           /*将Func函数的首地址赋给指针变量p*/
}

//static rt_uint8_t m_run_goHm_task_thread_create()
//{
//    /*
//     * There are several motors in use on this board, which can be obtained
//     *  from the motor configuration table
//     */
//    rt_uint8_t dirver_num = 0;
//    for (rt_uint8_t m_num = 1; m_num < MOTOR_TOTAL_NUM; m_num++)
//    {
//        //if(MyBoardMotor(m_num) == true)
//        {
//            //dirver_num = MotorDiverNum(m_num);
//            switch(dirver_num)
//            {
//                case 1:
//                    m_run_p[1] = rt_thread_create("m[1]_run",m1run_task, NULL, 512, 20, 5);
//                    if(m_run_p[1] == RT_NULL)
//                    {
//                        LOG_E("m1 run task creat failed.");
//                        return false;
//                    }
//                    m_gHm_p[1] = rt_thread_create("m[1]_gHm",m1gHm_task, NULL, 512, 20, 5);
//                    if(m_gHm_p[1] == RT_NULL)
//                    {
//                        LOG_E("m1 run task creat failed.");
//                        return false;
//                    }
//                    break;
//                case 2:
//                    m_run_p[2] = rt_thread_create("m[2]_run",m2run_task, NULL, 512, 20, 5);
//                    if(m_run_p[2] == RT_NULL)
//                    {
//                        LOG_E("m1 run task creat failed.");
//                        return false;
//                    }
//                    m_gHm_p[2] = rt_thread_create("m[2]_gHm",m2gHm_task, NULL, 512, 20, 5);
//                    if(m_gHm_p[2] == RT_NULL)
//                    {
//                        LOG_E("m1 run task creat failed.");
//                        return false;
//                    }
//
//                    break;
//                case 3:
//                    m_run_p[3] = rt_thread_create("m[3]_run",m3run_task, NULL, 512, 20, 5);
//                    m_gHm_p[3] = rt_thread_create("m[3]_gHm",m3gHm_task, NULL, 512, 20, 5);
//                    break;
//                case 4:
//                    m_run_p[4] = rt_thread_create("m[4]_run",m4run_task, NULL, 512, 20, 5);
//                    m_gHm_p[4] = rt_thread_create("m[4]_gHm",m4gHm_task, NULL, 512, 20, 5);
//                    break;
//                case 5:
//                    m_run_p[5] = rt_thread_create("m[5]_run",m5run_task, NULL, 512, 20, 5);
//                    m_gHm_p[5] = rt_thread_create("m[5]_gHm",m5gHm_task, NULL, 512, 20, 5);
//                    break;
//                case 6:
//                    m_run_p[6] = rt_thread_create("m[6]_run",m6run_task, NULL, 512, 20, 5);
//                    m_gHm_p[6] = rt_thread_create("m[6]_gHm",m6gHm_task, NULL, 512, 20, 5);
//                    break;
//                default:
//
//                    break;
//            }
//        }
//    }
//    return true;
//}

//static rt_uint8_t m_liquidDet_task_thread_create()
//{
//    rt_uint8_t dirver_num = 0;
//    //for (rt_uint8_t m_num = 1; m_num < MOTOR_TOTAL_NUM; m_num++)
//    {
//        //if(haveLiquiedDetection(m_num) == true)
//        {
//            //dirver_num = MotorDiverNum(m_num);
//            switch(dirver_num)
//            {
//                case 1:
//                    m_lqD_p[1] = rt_thread_create("m[1]_lqD",m1lqD_task, NULL, 512, 20, 5);
//                    if(m_run_p[1] == RT_NULL)
//                    {
//                        LOG_E("m1 liquied detection task creat failed.");
//                        return false;
//                    }
//                    break;
//                case 2:
//                    m_lqD_p[1] = rt_thread_create("m[2]_lqD",m2lqD_task, NULL, 512, 20, 5);
//                    break;
//                case 3:
//                    m_lqD_p[1] = rt_thread_create("m[1]_lqD",m1lqD_task, NULL, 512, 20, 5);
//                    break;
//                case 4:
//                    m_lqD_p[1] = rt_thread_create("m[1]_lqD",m1lqD_task, NULL, 512, 20, 5);
//                    break;
//                case 5:
//                    m_lqD_p[1] = rt_thread_create("m[1]_lqD",m1lqD_task, NULL, 512, 20, 5);
//                    break;
//                case 6:
//                    m_lqD_p[1] = rt_thread_create("m[1]_lqD",m1lqD_task, NULL, 512, 20, 5);
//                    break;
//                default:
//
//                    break;
//            }
//        }
//    }
//    return true;
//}

static rt_uint8_t action_queue_task_thread_create(void)
{

    return true;
}

rt_uint8_t thread_create(void)
{
    //Create motor related processes including motion, reset, and level detection
    //if(m_run_goHm_task_thread_create() != true)return false;
    //if(m_liquidDet_task_thread_create() != true)return false;
    //Create other device processe here

    //Create an action queue process here
    if(action_queue_task_thread_create() != true)return false;
    return true;
}

void GlobalVarInit(void)
{
    //
    //machine_info.addr = GetMachineAddr();
    machine_info.addr = 0x01;
}


static rt_uint32_t timems;

void StartTickMs(void)
{
    rt_thread_mdelay(1);
    timems++;
}

rt_uint32_t GetTickMs(void)
{
    return timems;
}

void DelayMs(rt_uint32_t ms)
{
    rt_thread_mdelay(ms);
}





